home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 6.6 KB | 254 lines | [TEXT/R*ch] |
- { Adjust Window Fkey }
- { A FKEY that allows you to specify the size and position of a window}
- { written by Matthew Xavier Mora mxmora@unix.sri.com 2-28-94 }
- { Copyright 1994 MXM Designs }
-
- unit AdjustWindow;
-
- interface
- {$IFC THINK_PASCAL=FALSE}
- uses
- Windows, TextEdit;
- {$ENDC}
- procedure main;
-
- implementation
-
- { ----------------------------------------------------------------------}
- procedure main;
- { ----------------------------------------------------------------------}
-
- var
- w: WindowPtr;
- r: Rect;
- te: array[1..4] of TeHandle;
- textlabel: array[1..4] of string[8];
- curW: WindowPtr;
- ok: ControlHandle;
- notDone: Boolean;
- evt: EventRecord;
- curTE: integer;
- ch: char;
- i: integer;
- temp: str255;
-
- { ----------------------------------------------------------------------}
- function abs (x: integer): integer;
- { ----------------------------------------------------------------------}
- begin
- if x < 0 then
- x := x * (-1);
- abs := x;
- end;
- { ----------------------------------------------------------------------}
- procedure AdjustWindowParams;
- { ----------------------------------------------------------------------}
- var
- t, l, b, r: longint;
- begin
-
- GetIText(te[1]^^.hText, temp);
- StringToNum(temp, t);
-
- GetIText(te[2]^^.hText, temp);
- StringToNum(temp, l);
-
- GetIText(te[3]^^.hText, temp);
- StringToNum(temp, b);
-
- GetIText(te[4]^^.hText, temp);
- StringToNum(temp, r);
-
- CloseWindow(w);
-
- MoveWindow(curW, l, t, true);
- SizeWindow(curW, abs(r - l), abs(b - t), true);
- end;
-
- { ----------------------------------------------------------------------}
- procedure DoMouse;
- { ----------------------------------------------------------------------}
- var
- part: integer;
- w: WindowPtr;
- ch: ControlHandle;
- p: Point;
- r: Rect;
- i: integer;
- begin
- p := evt.where;
- part := FindWindow(p, w);
- case part of
- inContent:
- begin
- GlobalToLocal(p);
- part := FindControl(p, w, ch);
- if ch <> nil then
- begin
- if TrackControl(ch, p, nil) <> 0 then
- notDone := false;
- end;
- for i := 1 to 4 do
- begin
- r := te[i]^^.viewRect;
- if PtInRect(p, r) then
- begin
- TEDeactivate(te[curTE]);
- curTe := i;
- TEActivate(te[curTE]);
- TEClick(p, false, te[curTE]);
- end;
- end;
-
- end;
- otherwise
- ;
-
- end;
-
-
- end;
- { ----------------------------------------------------------------------}
- procedure HandleKey;
- { ----------------------------------------------------------------------}
- begin
- ch := CHR(BAnd(evt.message, charCodeMask));
- if ch = chr(9) then
- begin
- TEDeactivate(te[curTE]);
- curTE := CurTE + 1;
- if curTE > 4 then
- curTE := 1;
- TEActivate(te[curTE]);
- end
- else
- TEKey(ch, te[curTE]);
- end;
- { ----------------------------------------------------------------------}
- procedure HandleUpdate;
- { ----------------------------------------------------------------------}
- var
- i: integer;
- wp: WindowPtr;
- begin
- wp := WindowPtr(evt.message);
- if (wp = w) then
- begin
- r := w^.portRect;
- SetPort(w);
- BeginUpdate(w);
-
- Moveto(10, 18);
- DrawString('Adjust Window Fkey by Matt Mora vers 1.0');
- UpdateControls(w, w^.visRgn);
- for i := 1 to 4 do
- begin
- TEUpdate(r, te[i]);
- r := te[i]^^.destRect;
- InsetRect(r, -2, -2);
- FrameRect(r);
- MoveTo(r.left - 52, r.bottom - 4);
- DrawString(textlabel[i]);
- end;
- EndUpdate(w);
- end;
- if (wp = curW) then
- begin
-
- BeginUpdate(curW);
-
- EndUpdate(curW);
- end;
-
- end;
-
- { ----------------------------------------------------------------------}
- procedure Terminate;
- { ----------------------------------------------------------------------}
-
- begin
- CloseWindow(w);
- CloseWindow(curW);
-
- end;
- begin
-
- {$IFC DEBUG=FALSE}
- curW := FrontWindow;
- {$ELSEC}
- SetRect(r, 20, 40, 400, 280);
- curW := NewWindow(nil, r, 'Adjust Window', true, documentProc,
- WindowPtr(-1), false, 0);
-
- {$ENDC}
-
- if curW <> nil then
- begin
- textlabel[1] := 'Top:';
- textlabel[2] := 'Left:';
- textlabel[3] := 'Bottom:';
- textlabel[4] := 'Right:';
-
- SetRect(r, 50, 100, 400, 280);
- w := NewWindow(nil, r, 'Adjust Window', true, dBoxProc,
- WindowPtr(-1), false, 0);
- SetPort(w);
- ShowWindow(w);
- SetRect(r, 250, 120, 300, 140);
- ok := NewControl(w, r, 'OK', true, 0, 0, 0, 0, 0);
- SetRect(r, 100, 30, 150, 48);
- te[1] := TENew(r, r);
-
- OffsetRect(r, 0, 28);
- te[2] := TENew(r, r);
-
- OffsetRect(r, 0, 28);
- te[3] := TENew(r, r);
-
- OffsetRect(r, 0, 28);
- te[4] := TENew(r, r);
- notDone := true;
- curTE := 1;
-
- TEActivate(te[curTE]);
- r := curW^.portRect;
- SetPort(curW);
- LocalToGlobal(r.topleft);
- LocalToGlobal(r.botRight);
- SetPort(w);
- NumToString(r.top, temp);
- TEInsert(ptr(ord(@temp) + 1), longint(temp[0]), te[1]);
- NumToString(r.left, temp);
- TEInsert(ptr(ord(@temp) + 1), longint(temp[0]), te[2]);
- NumToString(r.bottom, temp);
- TEInsert(ptr(ord(@temp) + 1), longint(temp[0]), te[3]);
- NumToString(r.right, temp);
- TEInsert(ptr(ord(@temp) + 1), longint(temp[0]), te[4]);
-
- while notDone do
- begin
- if WaitNextEvent(everyEvent, evt, 100, nil) then
- begin
- case evt.what of
- mouseDown:
- DoMouse;
- keyDown, autoKey:
- HandleKey;
- updateEvt:
- HandleUpdate;
- otherwise
- ;
- end;
- end
- else
- begin
- TEIdle(te[curTE]);
- end;
- end;
- end;
- AdjustWindowParams;
- { Terminate;}
- end;
-
- end.
-